package com.designpattern.structure.flyweight;

import java.util.HashMap;
import java.util.Map;

/**
 * @author chengze
 * @date 2022/11/30
 * @desc 享元工厂，维护一个对象池
 */
public class FlyweightFactory {

    private Map map = new HashMap();

    public FlyweightImpl getFlyweight(String key){
        if (map.get(key) == null){
            map.put(key,new FlyweightImpl(key));
        }
        return (FlyweightImpl) map.get(key);
    }
}
